/**
 * 一些浏览器环境的工具函数
 * @Author: zhangshubin
 * @Date: 2023-12-11 09:58:22
 * @Last Modified by: zhangshubin
 * @Last Modified time: 2023-12-13 10:28:30
 *  */

function getSystemFonts() {
  const div = document.createElement('div')
  div.style.fontFamily =
    '宋体,微软雅黑,楷体,Helvetica Neue,Arial,Noto Sans,sans-serif,Apple Color Emoji'
  document.body.appendChild(div)
  const styles = window.getComputedStyle(div)
  let fonts: string[] = []
  for (let i = 0; i < styles.length; i++) {
    if (styles[i] === 'font-family') {
      const f = styles.getPropertyValue('font-family')
      fonts = f
        .replace(/\"/g, '')
        .split(',')
        .map((item) => item.trimStart())
    }
  }
  document.body.removeChild(div)
  return fonts
}

const SystemFonts = getSystemFonts()
export { SystemFonts }
